package com.cssw.fyzb.busi.api.user;

import com.cssw.fyzb.core.model.vo.user.UserExtVo;
import com.cssw.fyzb.busi.service.user.UserExtService;
import com.cssw.fyzb.busi.service.user.UserRelService;
import com.cssw.fyzb.busi.service.user.UserService;
import com.cssw.fyzb.core.dao.user.DistrictDao;
import com.cssw.fyzb.core.model.dodb.UserExt;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 获取用户统计信息
 *
 * @author wondream
 */
@Function(description = "获取用户统计信息", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户标识", required = true)
})
@Component
public class GetUserStat implements Action {

    @Autowired
    private UserService userService;

    @Autowired
    private UserExtService userExtService;

    @Autowired
    private UserRelService userRelService;

    @Autowired
    private DistrictDao districtDao;

    private static final Logger logger = LoggerFactory.getLogger(GetUserInfo.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        UserExt userExt = userExtService.findById(userId);
        Integer followNum = userRelService.getFollowNum(userId);
        if(followNum==null){
            followNum=0;
        }
        UserExtVo userExtVo = new UserExtVo();
        userExtVo.setUserId(userExt.getUserId());
        userExtVo.setValidUser(userExt.getValidUser());
        userExtVo.setActiveNum(userExt.getActiveNum());
        userExtVo.setFans(userExt.getFans());
        userExtVo.setFriends(userExt.getFriends());
        userExtVo.setFollow(followNum);
        userExtVo.setProductions(userExt.getProductions());
        userExtVo.setLikes(userExt.getLikes());
        userExtVo.setAddActiveNum(userExt.getAddActiveNum());
        userExtVo.setTotalSendPack(userExt.getTotalSendPack());
        userExtVo.setSumSendPack(userExt.getSumSendPack());
        userExtVo.setTotalRecvPack(userExt.getTotalRecvPack());
        userExtVo.setSumRecvPack(userExt.getSumRecvPack());
        return Response.success().put("data", userExtVo);
    }
}
